<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script> 

        // 正则预定义类 
        // 都为字符类[] 多选一 
        // 大写为小写的取反
        // \d \D 
        // \w \W 
        // \s \S
        // \d 等价于[0-9]  ^\d$ 等价于 ^[0-9]$ (多选一)
        var rg = /^\d$/
        console.log(rg.test('1'));//true
        console.log(rg.test('2'));
        console.log(rg.test('3'));
        console.log(rg.test('11'));//false
        console.log(rg.test('22'));
        console.log(rg.test('33'));
        console.log('-----------');
        // \D 等价于 [^0-9]   取反 (匹配非数字)
        var rg = /^\D$/
        console.log(rg.test('1'));//false
        console.log(rg.test('2'));
        console.log(rg.test('3'));
        console.log(rg.test('11'));//false
        console.log(rg.test('22'));
        console.log(rg.test('33'));
        console.log(rg.test('a'));//true
        console.log(rg.test('A'));//true
        console.log(rg.test('!'));//true
        console.log(rg.test('_'));//true
        console.log('-----------');
        // \w 等价于 [a-zA-Z0-9_]  
        var rg1 = /^\w$/
        console.log(rg1.test('1'));//true
        console.log(rg1.test('2'));
        console.log(rg1.test('3'));
        console.log(rg1.test('11'));//false
        console.log(rg1.test('22'));
        console.log(rg1.test('33'));
        console.log(rg1.test('a'));//true
        console.log(rg1.test('A'));//true
        console.log(rg1.test('!'));//false
        console.log(rg1.test('_'));//true
        console.log('-----------');
        // \W 等价于 [^a-zA-Z0-9_]  取反 除所有字母数字下划线以为的字符 
        var rg11 = /^\W$/
        console.log(rg11.test('1'));//false
        console.log(rg11.test('2'));
        console.log(rg11.test('3'));
        console.log(rg11.test('11'));
        console.log(rg11.test('22'));
        console.log(rg11.test('33'));
        console.log(rg11.test('a'));
        console.log(rg11.test('A'));
        console.log(rg11.test('_'));
        console.log(rg11.test('!'));//true
        console.log(rg11.test('@'));//true
        console.log(rg11.test('^'));//true
        console.log('-----------');
        // \s 等价于 [\t\r\n\v\f]  匹配一个空格(即便是空格在中括号[]里也是多选一) (包括换行符 制表符 空格符等)
        var rg111 = /^\s$/
        console.log(rg111.test(' '));//true
        console.log(rg111.test('  '));//false
        console.log(rg111.test('2'));//false
        console.log(rg111.test('3'));
        console.log(rg111.test('11'));
        console.log(rg111.test('22'));
        console.log(rg111.test('33'));
        console.log(rg111.test('a'));
        console.log(rg111.test('A'));
        console.log(rg111.test('_'));
        console.log(rg111.test('!'));
        console.log(rg111.test('@'));
        console.log(rg111.test('^'));
        console.log('------------------------');
        // \S 等价于 [^\t\r\n\v\f]  取反 匹配非空格的字符
        var rg12 = /^\S$/
        // 别忘了这些预定义类都是多选1[] 未加量词符的前提下 只能选一个
        console.log(rg12.test(' '));//false 
        console.log(rg12.test('1'));//true 下面都是true  
        console.log(rg12.test('2'));
        console.log(rg12.test('3'));
        console.log(rg12.test('1'));
        console.log(rg12.test('2'));
        console.log(rg12.test('3'));
        console.log(rg12.test('a'));
        console.log(rg12.test('A'));
        console.log(rg12.test('-'));
        console.log(rg12.test('!'));
        console.log(rg12.test('#'));
        console.log(rg12.test('@'));


    </script>
</body>

</html>